package com.zzh.structuredeployment.activity

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.zzh.bridge.page.PageApp
import com.zzh.bridge_annotation.RouteTag
import com.zzh.custom.recycler.BaseChaosItem
import com.zzh.custom.recycler.ChaosAdapter
import com.zzh.custom.recycler.ChaosBean
import com.zzh.custom.recycler.ChaosViewHolder
import com.zzh.structuredeployment.R

@RouteTag(value = PageApp.CHAOS_LIST)
class ChaosListActivity : AppCompatActivity() {

    private val mRecyclerView by lazy {
        findViewById<RecyclerView>(R.id.mRecyclerView)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chaos_list)
        mRecyclerView.adapter =
            ChaosAdapter.createAdapter(
                createList(),
                BaseChaosItem1(),
                BaseChaosItem2(),
                BaseChaosItem3()
            )
    }

    private fun createList(): MutableList<out ChaosBean> {
        return arrayListOf<ChaosBean>().apply {
            add(Bean())
            add(Bean2())
            add(Bean3())
            add(Bean())
            add(Bean2())
            add(Bean3())
        }
    }

    companion object {
        class BaseChaosItem1 : BaseChaosItem<Bean, ChaosViewHolder1>() {

            override fun getChaosItemType(): Int {
                return 1
            }

            override fun onBindViewHolder(
                holder: ChaosViewHolder1,
                position: Int,
                bean: Bean?
            ) {
            }

            override fun createViewHolder(parent: ViewGroup): ChaosViewHolder1 {
                return ChaosViewHolder1(
                    LayoutInflater.from(parent.context)
                        .inflate(R.layout.loading_error, parent, false)
                )
            }
        }

        class BaseChaosItem2 : BaseChaosItem<Bean2, ChaosViewHolder2>() {

            override fun getChaosItemType(): Int {
                return 2
            }

            override fun onBindViewHolder(
                holder: ChaosViewHolder2,
                position: Int,
                bean: Bean2?
            ) {

            }

            override fun createViewHolder(parent: ViewGroup): ChaosViewHolder2 {
                return ChaosViewHolder2(
                    LayoutInflater.from(parent.context)
                        .inflate(R.layout.loading_empty, parent, false)
                )
            }
        }

        class BaseChaosItem3 : BaseChaosItem<Bean3, ChaosViewHolder3>() {

            override fun getChaosItemType(): Int {
                return 3
            }

            override fun onBindViewHolder(
                holder: ChaosViewHolder3,
                position: Int,
                bean: Bean3?
            ) {

            }

            override fun createViewHolder(parent: ViewGroup): ChaosViewHolder3 {
                return ChaosViewHolder3(
                    LayoutInflater.from(parent.context)
                        .inflate(R.layout.loading_loading, parent, false)
                )
            }
        }

        class ChaosViewHolder1(val rootView: View) : ChaosViewHolder(rootView) {

        }

        class ChaosViewHolder2(val rootView: View) : ChaosViewHolder(rootView) {

        }

        class ChaosViewHolder3(val rootView: View) : ChaosViewHolder(rootView) {

        }


        class Bean : ChaosBean {
            override fun getChaosItemType(): Int {
                return 1
            }

        }

        class Bean2 : ChaosBean {
            override fun getChaosItemType(): Int {
                return 2
            }

        }

        class Bean3 : ChaosBean {
            override fun getChaosItemType(): Int {
                return 3
            }
        }
    }


}